package com.zprmb.udzt;

import java.text.DecimalFormat;

import org.json.JSONObject;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;

import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.VolleryUtil;


public class First_Invest extends BaseActivity {
	private double firstamount;
	private TextView ex_gold;
	private ImageView img_an_niu,img_xx;
	private String ref;
	private DecimalFormat df = new DecimalFormat("###0");
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.first_invest);
		ex_gold=(TextView)findViewById(R.id.ex_gold);
		ex_gold.setText(getIntent().getStringExtra("firstamount")+"");
		img_an_niu=(ImageView)findViewById(R.id.img_anniu);
		img_xx=(ImageView)findViewById(R.id.img_xx);
		ref=getShare().getString("usercode", "");
		img_xx.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		img_an_niu.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				initshare();
			}
		});
	}
	private void initshare(){
		VolleryUtil volleryUtil=new VolleryUtil() {
			
			@Override
			public void onUpDate(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.e("invate", jsonObject.toString());
				if(jsonObject.optInt("success")==1){
					JSONObject json=jsonObject.optJSONObject("data");
					String linkurl="";
					if(ref.equals("")){
						linkurl= json.optString("linkUrl");
						
					}else{
						linkurl=  json.optString("linkUrl")+"?ref="+ref;
						
					}
					
					
					share(First_Invest.this, json.optString("description"), json.optString("title"), linkurl, "");
				}else{
				 	
				}
			}
			
			@Override
			public void onError() {
				// TODO Auto-generated method stub
				
			}
		};
		volleryUtil.setRequestMethod(0);
		volleryUtil.setShow(true);
		volleryUtil.execute(First_Invest.this, Constant.URL+"/api/shareProductContent/inviteFriend/inviteFriend", "");
	}
//	 private void shareLogin(){
//			
//			Intent intent = new Intent(First_Invest.this,WXEntryActivity.class);
//			if(ref.equals("")){
//				intent.putExtra("sharelink", Constant.URL+"/h5/expGain?app=true");
//			}else{
//				intent.putExtra("sharelink", Constant.URL+"/h5/expGain?app=true&userCode="+ref);
//			}
//			
//				
//			
//			intent.putExtra("description", "优点智投“七月司庆趴,现金欢乐送”,百万礼金，好友同享,友谊的小船永不翻~");
//			intent.putExtra("title", "优点智投壕送2万体验金，新用户免费体验投资，我出本金，你拿收益！");
//			startActivity(intent);
//			finish();
//		
//}
}
